home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / greasemonkey-0.8.20080609.0-fx.xpi / chrome / greasemonkey.jar / chromeFiles / content / install.js < prev    next >
Text File  |  2008-06-09  |  4KB  |  118 lines

  1. var GMInstall = {
  2.   init: function() {
  3.     var ioservice = Components.classes["@mozilla.org/network/io-service;1"]
  4.                               .getService(Components.interfaces.nsIIOService);
  5.  
  6.     this.htmlNs_ = "http://www.w3.org/1999/xhtml";
  7.  
  8.     this.scriptDownloader_ = window.arguments[0];
  9.     this.script_ = this.scriptDownloader_.script;
  10.  
  11.     this.setupIncludes("includes", "includes-desc", this.script_.includes);
  12.     this.setupIncludes("excludes", "excludes-desc", this.script_.excludes);
  13.  
  14.     this.dialog_ = document.documentElement;
  15.     this.extraButton_ = this.dialog_.getButton("extra1");
  16.     this.extraButton_.setAttribute("type", "checkbox");
  17.  
  18.     this.acceptButton_ = this.dialog_.getButton("accept");
  19.     this.acceptButton_.baseLabel = this.acceptButton_.label;
  20.  
  21.     this.timer_ = null;
  22.     this.seconds_ = 0;
  23.     this.startTimer();
  24.  
  25.     this.bundle = document.getElementById("gm-browser-bundle");
  26.     this.greetz = new Array();
  27.     for(var i = 0; i < 6; i++){
  28.       this.greetz.push(this.bundle.getString("greetz." + i));
  29.     }
  30.  
  31.     var pick = Math.round(Math.random() * (this.greetz.length - 1));
  32.     var heading = document.getElementById("heading");
  33.     heading.appendChild(document.createElementNS(this.htmlNs_, "strong"));
  34.     heading.firstChild.appendChild(document.createTextNode(this.greetz[pick]));
  35.     heading.appendChild(document.createTextNode(" " + this.bundle.getString("greeting.msg")));
  36.  
  37.     var desc = document.getElementById("scriptDescription");
  38.     desc.appendChild(document.createElementNS(this.htmlNs_, "strong"));
  39.     desc.firstChild.appendChild(document.createTextNode(this.script_.name));
  40.     desc.appendChild(document.createElementNS(this.htmlNs_, "br"));
  41.     desc.appendChild(document.createTextNode(this.script_.description));
  42.   },
  43.  
  44.   onFocus: function(e) {
  45.     this.startTimer();
  46.   },
  47.  
  48.   onBlur: function(e) {
  49.     this.stopTimer();
  50.   },
  51.  
  52.   startTimer: function() {
  53.     this.seconds_ = 4;
  54.     this.updateLabel();
  55.  
  56.     if (this.timer_) {
  57.       window.clearInterval(this.timer_);
  58.     }
  59.  
  60.     this.timer_ = window.setInterval(function() { GMInstall.onInterval() }, 500);
  61.   },
  62.  
  63.   onInterval: function() {
  64.     this.seconds_--;
  65.     this.updateLabel();
  66.  
  67.     if (this.seconds_ == 0) {
  68.       this.timer_ = window.clearInterval(this.timer_);
  69.     }
  70.   },
  71.  
  72.   stopTimer: function() {
  73.     this.seconds_ = 5;
  74.     this.timer_ = window.clearInterval(this.timer_);
  75.     this.updateLabel();
  76.   },
  77.  
  78.   updateLabel: function() {
  79.     if (this.seconds_ > 0) {
  80.       this.acceptButton_.focus();
  81.       this.acceptButton_.disabled = true;
  82.       this.acceptButton_.label = this.acceptButton_.baseLabel + " (" + this.seconds_ + ")";
  83.     } else {
  84.       this.acceptButton_.disabled = false;
  85.       this.acceptButton_.label = this.acceptButton_.baseLabel;
  86.     }
  87.   },
  88.  
  89.   setupIncludes: function(box, desc, includes) {
  90.     if (includes.length > 0) {
  91.       desc = document.getElementById(desc);
  92.       document.getElementById(box).style.display = "";
  93.  
  94.       for (var i = 0; i < includes.length; i++) {
  95.         desc.appendChild(document.createTextNode(includes[i]));
  96.         desc.appendChild(document.createElementNS(this.htmlNs_, "br"));
  97.       }
  98.  
  99.       desc.removeChild(desc.lastChild);
  100.     }
  101.   },
  102.  
  103.   onOK: function() {
  104.     this.scriptDownloader_.installScript();
  105.     window.setTimeout("window.close()", 0);
  106.   },
  107.  
  108.   onCancel: function(){
  109.     this.scriptDownloader_.cleanupTempFiles();
  110.     window.close();
  111.   },
  112.  
  113.   onShowSource: function() {
  114.     this.scriptDownloader_.showScriptView();
  115.     window.setTimeout("window.close()", 0);
  116.   }
  117. };
  118.